package brainsplash.gyrusscope.game;

import java.util.List;

import javax.microedition.khronos.opengles.GL10;

import brainsplash.gyrusscope.framework.Game;
import brainsplash.gyrusscope.framework.Input.TouchEvent;
import brainsplash.gyrusscope.framework.gl.Camera2D;
import brainsplash.gyrusscope.framework.gl.SpriteBatcher;
import brainsplash.gyrusscope.framework.impl.GLScreen;
import brainsplash.gyrusscope.framework.math.OverlapTester;
import brainsplash.gyrusscope.framework.math.Rectangle;
import brainsplash.gyrusscope.framework.math.Vector2;

public class OptionsMenuScreen  extends GLScreen {
	//vibration
	//orientation
	//	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	//  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	//	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	//controls (touch/keyboard/accelerometer)
	//debug mode
	//FPS
	//volume sound effects
	//volume music
	
    Camera2D guiCam;
    Vector2 touchPoint;
    SpriteBatcher batcher;
    
    Rectangle vibrateBounds;
    Rectangle orientBounds;
    Rectangle controlBounds;
    Rectangle debugBounds;
    Rectangle soundBounds;
    Rectangle musicBounds;
    Rectangle fpsBounds;

	public OptionsMenuScreen(Game game) {
		super(game);
        touchPoint = new Vector2();
        
        vibrateBounds = new Rectangle(0, 10, 300, 36);
        orientBounds = new Rectangle(0, 20, 300, 36);
        controlBounds = new Rectangle(0, 30, 300, 36);
        debugBounds = new Rectangle(0, 40, 300, 36);
        soundBounds = new Rectangle(0, 40, 300, 36);
        musicBounds = new Rectangle(0, 40, 300, 36);
        fpsBounds = new Rectangle(0, 40, 300, 36);
        
	}

	@Override
	public void update(float deltaTime) {
        List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
        game.getInput().getKeyEvents();
        
        for(int i = 0; i < touchEvents.size(); i++) {
            TouchEvent event = touchEvents.get(i);
            if(event.type == TouchEvent.TOUCH_UP) {
                touchPoint.set(event.x, event.y);
                guiCam.touchToWorld(touchPoint);
                
                if(OverlapTester.pointInRectangle(vibrateBounds, touchPoint)) {
                    Assets.playSound(Assets.clickSound);
                    return;
                }
                else if(OverlapTester.pointInRectangle(orientBounds, touchPoint)) {
                    Assets.playSound(Assets.clickSound);
                    return;
                }
                else if(OverlapTester.pointInRectangle(controlBounds, touchPoint)) {
                    Assets.playSound(Assets.clickSound);
                }
                else if(OverlapTester.pointInRectangle(debugBounds, touchPoint)) {
                    Assets.playSound(Assets.clickSound);
                }
                else if(OverlapTester.pointInRectangle(soundBounds, touchPoint)) {
                    Assets.playSound(Assets.clickSound);
                }
                else if(OverlapTester.pointInRectangle(musicBounds, touchPoint)) {
                    Assets.playSound(Assets.clickSound);
                }
                else if(OverlapTester.pointInRectangle(fpsBounds, touchPoint)) {
                    Assets.playSound(Assets.clickSound);
                }
            }
        }
    }

	@Override
	public void present(float deltaTime) {
        GL10 gl = glGraphics.getGL();        
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        guiCam.setViewportAndMatrices();
        
        gl.glEnable(GL10.GL_TEXTURE_2D);
        
        batcher.beginBatch(Assets.background);
        batcher.drawSprite(160, 240, 320, 480, Assets.backgroundRegion);
        batcher.endBatch();
        
        gl.glEnable(GL10.GL_BLEND);
        gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
        
        batcher.beginBatch(Assets.items);
        for (int j = 0; j < Particles.partSystems.size(); j++) {
        	ParticleSystem ps = Particles.partSystems.get(j);
	        for(int i = 0; i < ps.particles.size(); i++) {
	        	BaseObject gobject = ps.particles.get(i);
	        	float offset = Math.signum(gobject.speed) * 90;
	        	if (offset == 0) {offset = 90;}
	            batcher.drawSprite(gobject.x, gobject.y, gobject.size, gobject.size, gobject.direction + offset, gobject.sprite);
	        }
        }
        
        batcher.endBatch();
        
        gl.glDisable(GL10.GL_BLEND);
    }

	@Override
	public void pause() {
	}

	@Override
	public void resume() {
	}

	@Override
	public void dispose() {
	}
}
